# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     education
   Description :
   Author :       Flyoung
   date：          2023/9/5
-------------------------------------------------
   Change Activity:
                   2023/9/5:
-------------------------------------------------
"""
from sqlalchemy import Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import Session

from db.common import with_session

Base = declarative_base()


class Education(Base):
    __tablename__ = 'education'

    education_id = Column(Integer, primary_key=True, autoincrement=True)
    education_name = Column(String(255), nullable=True)
    education_score = Column(Float, nullable=True)

    def __init__(self, education_name, education_score):
        self.education_name = education_name
        self.education_score = education_score

    def to_dict(self):
        return {
            'education_id': self.education_id,
            'education_name': self.education_name,
            'education_score': self.education_score
        }


@with_session
def get_all_education(session: Session):
    return [i.to_dict() for i in session.query(Education).all()]


@with_session
def add_education(session: Session, education_name: str, education_score=0):
    education = Education(education_name, education_score)
    session.add(education)
    return education.to_dict()
